package com.hanyizhu.demostore.service.impl;

import com.hanyizhu.demostore.entity.Product;
import com.hanyizhu.demostore.mapper.ProductMapper;
import com.hanyizhu.demostore.service.IProductService;
import com.hanyizhu.demostore.service.ex.ProuductNoFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lenovo
 */
@Service
public class ProductServiceImpl implements IProductService{

    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<Product> findHotList() {
        //        for (Product product:list
//             ) {
//            product.setPriority(null);
//            product.setCreatedUser(null);
//            product.setCreatedTime(null);
//            product.setModifiedTime(null);
//            product.setModifiedUser(null);
//        }
        return productMapper.findHotList();
    }

    @Override
    public Product findById(Integer id) {
        Product product = productMapper.findById(id);
        if (product == null){
            throw new ProuductNoFoundException("商品不存在");
        }
        return product;
    }
}
